##########################################################################################
### Replication Code: Demographics Tables (Appendix E)                         ###########
### Title: Interstate Conciliation in the Shadow of Deep Historical Grievances ###########
### Authors: Kai Quek and Jiaqian Ni                                           ###########
### Date: January 30, 2026                                                     ###########
##########################################################################################



######################## Chinese Sample ######################
##############################################################
rm(list = ls())
setwd("~/Desktop/Projects/Survey 2023/data analysis") 
# set your working directory here, which should also contain the survey data


# load data 
apchina <- readRDS("Conciliate_China.RData") #cleaned data created in "analysis_all.R" 

# gender (male=1)
table(apchina$gender)
g <-prop.table(table(apchina$gender))
paste(round(g*100, 1), "%", sep = "")

# region
table(apchina$region)
apchina$area <- NA
apchina$area[apchina$region==3|apchina$region==30|apchina$region==11|
            apchina$region==28|apchina$region==17] <- 1 
apchina$area[apchina$region==21|apchina$region==20|apchina$region==12] <- 2
apchina$area[apchina$region==27|apchina$region==18|apchina$region==34|
            apchina$region==2|apchina$region==5|apchina$region==19|apchina$region==26] <- 3
apchina$area[apchina$region==13|apchina$region==15|apchina$region==16|
            apchina$region==7|apchina$region==8|apchina$region==10] <- 4
apchina$area[apchina$region==4|apchina$region==29|apchina$region==9|
            apchina$region==33|apchina$region==31] <- 5
apchina$area[apchina$region==25|apchina$region==6|apchina$region==24|
            apchina$region==23|apchina$region==32] <- 6
apchina$area[apchina$region==14|apchina$region==22|apchina$region==35]<- 7
table(apchina$area)
a <- prop.table(table(apchina$area))
paste(round(a*100, 1), "%", sep = "")

# age
apchina$agegroup <- NA
apchina$agegroup[apchina$age <=19] <- 1
apchina$agegroup[apchina$age >=20 & apchina$age <=29] <- 2
apchina$agegroup[apchina$age >=30 & apchina$age <=39] <- 3
apchina$agegroup[apchina$age >=40 & apchina$age <=49] <- 4
apchina$agegroup[apchina$age >=50 & apchina$age <=59] <- 5
apchina$agegroup[apchina$age >=60] <- 6
table(apchina$agegroup)
b <- prop.table(table(apchina$agegroup))
paste(round(b*100, 1), "%", sep = "")

## household income
summary(as.numeric(apchina$income1))

## ethnicity
table(apchina$race)
c<- prop.table(table(apchina$race))
paste(round(c*100, 1), "%", sep = "")


######################## Japanese Sample ###########################
###################################################################
rm(list = ls())
setwd("~/Desktop/Survey 2023/data analysis")

## load dataset
japan <- readRDS("Conciliate_Japan.RData")

# gender (male=1)
table(japan$gender)
g <-prop.table(table(japan$gender))
paste(round(g*100, 1), "%", sep = "")

# age
japan$agegroup <- NA
japan$agegroup[japan$age >=18 & japan$age <=24] <- 1
japan$agegroup[japan$age >=25 & japan$age <=34] <- 2
japan$agegroup[japan$age >=35 & japan$age <=44] <- 3
japan$agegroup[japan$age >=45 & japan$age <=54] <- 4
japan$agegroup[japan$age >=55 & japan$age <=64] <- 5
japan$agegroup[japan$age >=65 & japan$age <=74] <- 6

b <- prop.table(table(japan$agegroup))
paste(round(b*100, 1), "%", sep = "")

# region 
table(japan$region)
japan$area <- NA
japan$area[japan$region <=7] <- 1 # Hokkaido & Tohoku
japan$area[japan$region >=8 & japan$region <=14] <- 2 # Kanto
japan$area[japan$region >=15 & japan$region <=23] <- 3 # Chubu
japan$area[japan$region >=24& japan$region <=30] <- 4  # Kansai
japan$area[japan$region >=31 & japan$region <=39] <- 5 # Chugoku & Shikoku 
japan$area[japan$region >=40 & japan$region <=47] <- 6 # Kyushu & Okinawa 

table(japan$area)
a <- prop.table(table(japan$area))
paste(round(a*100, 1), "%", sep = "")

# income 
summary(japan$income)

# korean/chinese 
paste(round(prop.table(table(japan$korean_chinese))*100,1),"%",sep = "")


######################## American Sample ###########################
###################################################################
rm(list = ls())
setwd("~/Desktop/Survey 2023/data analysis")

usa <- readRDS("Conciliate_USA.RData")

# gender (male=1)
g <-prop.table(table(usa$gender))
paste(round(g*100, 1), "%", sep = "")

# age
usa$agegroup <- NA
usa$agegroup[usa$age >=18 & usa$age <=24] <- 1
usa$agegroup[usa$age >=25 & usa$age <=34] <- 2
usa$agegroup[usa$age >=35 & usa$age <=44] <- 3
usa$agegroup[usa$age >=45 & usa$age <=54] <- 4
usa$agegroup[usa$age >=55 & usa$age <=64] <- 5
usa$agegroup[usa$age >=65 ] <- 6

g <-prop.table(table(usa$agegroup))
paste(round(g*100, 1), "%", sep = "")

# race
g <-prop.table(table(usa$racial))
paste(round(g*100, 1), "%", sep = "")

g <-prop.table(table(usa$hispanic))
paste(round(g*100, 1), "%", sep = "")

# income
paste(round(prop.table(table(usa$income))*100,1),"%",sep = "")
usa$incomegroup <- NA
usa$incomegroup[usa$income ==1 | usa$income==2] <- 1
usa$incomegroup[usa$income ==3 | usa$income==4] <- 2
usa$incomegroup[usa$income >=5 & usa$income<=7] <- 3
usa$incomegroup[usa$income >=8 & usa$income<=12] <- 4
usa$incomegroup[usa$income ==13 | usa$income==14] <- 5
usa$incomegroup[usa$income >= 15 & usa$income<=17] <- 6
paste(round(prop.table(table(usa$incomegroup))*100,1),"%",sep = "")















